<?php
/**
 * Menu.php
 * 
 * @category   Naneau
 * @package    Naneau_Action_Helper
 * @copyright  Copyright (c) 2007 Maurice Fonk - http://naneau.nl
 * @version    0.1
 */

/** base class */
require_once 'Zend/Controller/Action/Helper/Abstract.php';

/**
 * Naneau_Action_Helper_Menu
 * 
 * a helper for building menu items automatically
 *
 * @category   Naneau
 * @package    Naneau_Action_Helper
 * @copyright  Copyright (c) 2007 Maurice Fonk - http://naneau.nl
 */
class Naneau_Controller_Action_Helper_Menu extends Zend_Controller_Action_Helper_Abstract {

    /**
     * the view renderer
     *
     * @var Zend_View
     */
    private $_view;

    public function __construct() {

        $this->_view = Zend_Controller_Action_HelperBroker::getExistingHelper('viewRenderer')->view;
        //view renderer action helper -> view
        
        $this->_view->menu = array();
    }

    /**
     * add a menu item
     *
     * @param string $title
     * @param string $description
     * @param string $url
     * @param bool $active
     * @return Naneau_Action_Helper_Menu 
     */
    public function addItem($title, $description, $url, $active = false) {
        $this->_view->menu[$title] = array(
        'url' => $url,
        'description' => $description,
        'active' => $active
        );

        if ($active) {
            $this->setActive($title);
        }

        return $this;
    }

    /**
     * flag a menu item to be active
     * @param string $title
     * @param bool $flag
     * @return Naneau_Action_Helper_Menu
     */
    public function setActive($title, $flag = true) {
        foreach ($this->_view->menu as $key => $item) {
            $this->_view->menu[$key]['active'] = false;
        }
        //reset all
        $this->_view->menu[$title]['active'] = true;
        //set active
        return $this;
    }
}